package com.atguigu.gmall.search.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.search.Goods;
import com.atguigu.gmall.search.service.SearchService;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//接收 远程调用
@RestController
@RequestMapping("/api/inner/rpc/search")
public class SearchRpcController {

    @Autowired
    SearchService searchService;

    //增加热度分
    @GetMapping("/hotscore/{skuId}/{score}")
    public Result updateHotScore(@PathVariable("skuId") Long skuId,@PathVariable("score") Long score){
        searchService.updateHotScore(skuId,score);
        return Result.ok();
    }

    //检索商品
    @PostMapping("/searchgoods")
    public Result<SearchRespVo> search(@RequestBody SearchParamVo searchParamVo){
        SearchRespVo respVo= searchService.search(searchParamVo);
        return Result.ok(respVo);
    }

    //商品上架，接收service-product的调用
    @PostMapping("/up/goods")
    public Result onSale(@RequestBody Goods goods){
        searchService.up(goods);
        return Result.ok();
    }
    //商品下架，接收service-product的调用
    @GetMapping("/down/goods/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        searchService.down(skuId);
        return Result.ok();
    }
}
